﻿
function gel(id) { return document.getElementById(id);}

var AjaxHelper = {
    /*发送get请求*/
    doGet: function (url, data, callbackFunc) {
        this.doAjax("get", url, data, callbackFunc);
    },
    /*发送post请求*/
    doPost: function (url, data, callbackFunc) {
        this.doAjax("post", url, data, callbackFunc);
    },
    /*指定发送方式*/
    doAjax: function (method,url,data,callbackFunc) {
        method= method.toLowerCase();
        var xhr = new XMLHttpRequest();
        xhr.open(method, url + (method == "get" ? "?" + data : ""), true);
        if (method == "get") {
            xhr.setRequestHeader("If-Modified-Since", "0");
        } else {
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        }
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    callbackFunc(xhr);
                } else {
                    alert("响应报文状态码异常：" + xhr.status);
                }
            }
        };
        xhr.send((method == "post" ? data : null));
    }
};

//将序列化成json格式后日期(毫秒数)转成日期格式
function changeDateFormat(cellval) {
    var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    return date.getFullYear() + "-" + month + "-" + currentDate;
}

//var ajaxH = new Object();
//ajaxH.doAjax = function () {
//};